"""
多线程-使用Thread类

Version: 0.1
Author: yuwl
Date：2024-4-9
"""

from random import randint
from threading import Thread
from time import time, sleep

def download_task(filename):
    print('开始下载%s...' % filename)
    time_to_download = randint(5, 10)
    sleep(time_to_download)
    print('%s下载完成！耗费了%d秒' % (filename, time_to_download))

def main():
    strat = time()
    p1 = Thread(target=download_task, args=('Python入门', ))
    p1.start()
    p2 = Thread(target=download_task, args=('file.avi', ))
    p2.start()
    # 等待进程执行结束
    p1.join()
    p2.join()
    end = time()
    print('总共耗费了%.2f秒.' % (end - strat))


if __name__ == '__main__':
    main()